import Mock from "mockjs";
Mock.setup({
  timeout: "100-200",
});

const users = [
  {
    id: 1,
    name: "admin", //用户名
    password: "123456", //密码
    token: "adminadminadmin",
  },
  {
    id: 2,
    name: "zhangsan",
    password: "123456",
    token: "zhangsanzhangsan",
  },
];

const routers: any = {
  admin: [
    {
      path: "/channelManage",
      name: "channelManage",
      title: "渠道管理",
      operation: ["add","edit","delete","copy"],
      icon: "fa el-icon-s-operation",
    },
    {
      path: "/commodityManage",
      name: "commodityManage",
      title: "商品管理",
      icon: "fa el-icon-goods",
    },
    {
      path: "/contentManage",
      name: "contentManage",
      title: "内容管理",
      icon: "fa el-icon-folder",
      children: [
        {
          path: "/content",
          name: "content",
          title: "内容配置",
          icon: "fa el-icon-tickets",
        },
        {
          path: "/idiom",
          name: "idiom",
          title: "内容列表A",
          icon: "fa el-icon-connection",
        },
        {
          path: "/riddles",
          name: "riddles",
          title: "内容列表B",
          icon: "fa el-icon-link",
        },
      ],
    },
    {
      path: "/operationLog",
      name: "operationLog",
      title: "操作日志",
      icon: "fa el-icon-document",
    },
  ],
  zhangsan: [
    {
      path: "/channelManage",
      name: "channelManage",
      title: "渠道管理",
      icon: "fa el-icon-s-operation",
    },
    {
      path: "/contentManage",
      name: "contentManage",
      redirect: "/content",
      title: "内容管理",
      icon: "fa el-icon-folder",
      children: [
        {
          path: "/content",
          name: "content",
          title: "内容配置",
          icon: "fa el-icon-tickets",
        },
        {
          path: "/idiom",
          name: "idiom",
          title: "内容列表A",
          icon: "fa el-icon-connection",
        },
        {
          path: "/riddles",
          name: "riddles",
          title: "内容列表B",
          icon: "fa el-icon-link",
        },
      ],
    },
  ],
};

//用户登录
Mock.mock("/login", "post", (options: any) => {
  const { username, pwd } = JSON.parse(options.body);
  const user = users.find(
    (item) => item.name === username && item.password === pwd
  );
  if (user) {
    return {
      code: 0,
      status: 200,
      data: user,
    };
  } else {
    return {
      code: 10001,
      status: 200,
      data: null,
    };
  }
});

//获取动态路由

Mock.mock("/getRouters", "post", (options: any) => {
  const { key } = JSON.parse(options.body);
  return {
    code: 0,
    status: 200,
    data: routers[key],
  };
});

var channelData = Mock.mock({
  "data|10": [
    {
      name: "@cname", //中文名称
      "appID|1-100": 100, //100以内随机整数
      "className|1-100": 100, //100以内随机整数
      "type|1-100": 100, //100以内随机整数
      "huilv|1-100": 100, //100以内随机整数
      "banben|1-5": 1, //100以内随机整数
      "code|1-5": 1,
      createTime: '@date("yyyy-MM-dd")', //日期
    },
  ],
});

Mock.mock("/msdk/getChannel", "get", () => {
  return {
    code: 0,
    status: 200,
    data: channelData.data,
  };
});

Mock.mock(/\/msdk\/getIdiom/, {
  code: 0,
  status: 200,

  "data|10": [
    {
      name: "@cname", //中文名称
      "image|1-100": 100, //100以内随机整数
      "answer|1-100": 100, //100以内随机整数
      "content|1-100": 100, //100以内随机整数
      "explain|1-5": 1, //100以内随机整数
    },
  ],
});

Mock.mock(/\/msdk\/getRiddles/, {
  code: 0,
  status: 200,

  "data|10": [
    {
      name: "@cname", //中文名称
      title: "@cname", //100以内随机整数
      "answer|1-100": 100, //100以内随机整数
      "content|1-100": 100, //100以内随机整数
      "explain|1-5": 1, //100以内随机整数
    },
  ],
});

Mock.mock(/\/msdk\/getOrder/, {
  code: 0,
  status: 200,

  "data|10": [
    {
      "uid|1-100": 100, //100以内随机整数
      app: "这是一个app", //100以内随机整数
      "money|1-100": 100, //100以内随机整数
      "address|1-100": 100, //100以内随机整数
      name: "@cname", //100以内随机整数
      createTime: '@date("yyyy-MM-dd")', //日期
      "status|1": ["交易成功", "审核中", "交易失败"], //100以内随机整数
      reason: "@cname", //100以内随机整数
      "isTui|1": ["是", "否"], //100以内随机整数
    },
  ],
});

Mock.mock(/\/msdk\/getBlackList/, {
  code: 0,
  status: 200,

  "data|10": [
    {
      "uid|1-100": 100, //100以内随机整数
      app: "这是一个app", //100以内随机整数
      "money|1-100": 100, //100以内随机整数
      "address|1-100": 100, //100以内随机整数
      name: "@cname", //100以内随机整数
      createTime: '@date("yyyy-MM-dd")', //日期
      "status|1": ["交易成功", "审核中", "交易失败"], //100以内随机整数
      reason: "@cname", //100以内随机整数
      "isTui|1": ["是", "否"], //100以内随机整数
    },
  ],
});
